package com.mobiletrain.org.motherkitch.shouye;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/4/26.
 */
public class TodayAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<Today> data;

    public TodayAdapter(Context context, ArrayList<Today> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.shouye_list_item1,null);
            holder.title = (TextView) convertView.findViewById(R.id.shouye_title);
            holder.content= (TextView) convertView.findViewById(R.id.shouye_content);
            holder.image= (ImageView) convertView.findViewById(R.id.shouye_image);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        Today info = data.get(position);
        holder.title.setText(info.getTitle());
        holder.content.setText(info.getContent());
        BitmapUtils bitmapUtils = ImageLoad.getBitmapUtils(context);
        bitmapUtils.display(holder.image, info.getPic());
        return convertView;
    }
    class ViewHolder{
        TextView title;
        TextView content;
        ImageView image;
    }
}
